//package com.ling.pl.core.commons.utils;
//
//import net.sf.ehcache.hibernate.HibernateUtil;
//import org.hibernate.Session;
//import org.hibernate.SessionFactory;
//
//import javax.persistence.EntityManager;
//import javax.persistence.EntityManagerFactory;
//import javax.persistence.spi.PersistenceProvider;
//
///**
// * Created by bo.wang on 2017/1/1.
// */
//public class HibernateUtils {
//
//    private EntityManagerFactory emf;
//
//    private SessionFactory sf;
//
//    public Session getSession() {
//        return getSessionFactory().openSession();
//    }
//
//    public EntityManager getEntityManager() {
//        return getEntityManagerFactory().createEntityManager();
//    }
//
//    private EntityManagerFactory getEntityManagerFactory() {
//        if (emf == null) {
//            Bundle thisBundle = FrameworkUtil.getBundle(HibernateUtils.class);
//            BundleContext context = thisBundle.getBundleContext();
//
//            ServiceReference serviceReference = context.getServiceReference(PersistenceProvider.class.getName());
//            PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService(serviceReference);
//
//            emf = persistenceProvider.createEntityManagerFactory("YourPersistenceUnitName", null);
//        }
//        return emf;
//    }
//
//    private SessionFactory getSessionFactory() {
//        if (sf == null) {
//            Bundle thisBundle = FrameworkUtil.getBundle(HibernateUtil.class);
//            BundleContext context = thisBundle.getBundleContext();
//
//            ServiceReference sr = context.getServiceReference(SessionFactory.class.getName());
//            sf = (SessionFactory) context.getService(sr);
//        }
//        return sf;
//    }
//}
